package com.sky.mapper;

import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 动态查询购物车
     *
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> getById(ShoppingCart shoppingCart);

    /**
     * 修改用户购物车数据
     * @param shoppingCart
     */
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    void updateNumber(ShoppingCart shoppingCart);

    /**
     * 根据菜品id查询菜品表
     * @param dishId
     * @return
     */
    @Select("select * from dish where id=#{dishId}")
    Dish selectDish(Long dishId);

    /**
     * 根据套餐id查询套餐
     * @param setmealId
     * @return
     */
    @Select("select * from setmeal where id=#{setmealId}")
    Setmeal selectSetmeal(Long setmealId);

    /**
     * 插入用户购物车数据
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name, image, user_id, dish_id," +
            " setmeal_id, dish_flavor, amount,number," +
            " create_time) VALUES (#{name},#{image},#{userId}" +
            ",#{dishId},#{setmealId},#{dishFlavor},#{amount},#{number},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 清空购物车
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id=#{userId}")
    void Clean(Long userId);

    /**
     * 动态删除购物车的商品
     * @param shop
     */
    void delById(ShoppingCart shop);

    /**
     * 批量插入购物车表
     * @param cartList
     */
    void insertCartList(List<ShoppingCart> cartList);
}
